<?php
// 評語資料升級
class Default_Model_Upgrade_Comment extends Default_Model_Upgrade_Core
{
    protected $_table = 'comment';
    protected $_targetTable = array('comment_level','comment_kind','comment');

    function upgrade (){
        if ($this->isUpgrade())
        return 'isUpgrde';
        else {
              $query = "SELECT a.*,b.teacher_sn FROM comment_level a  LEFT JOIN teacher_base b ON a.level_teacher_id=b.teach_id";
//echo $query;
            $res = $this->_sfs3Pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
            foreach($res as $row) {
                $arr = array();
                $arr['name'] = $this->iconv($row['level_name']);
                $arr['teacher_sn'] = $row['teacher_sn'];
                $this->fromArray('comment_level',$arr);
            }

            $query = "SELECT a.*,b.teacher_sn FROM comment_kind a  LEFT JOIN teacher_base b ON a.kind_teacher_id=b.teach_id";
//echo $query;
            $res = $this->_sfs3Pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
            foreach($res as $row) {
                $arr = array();
                $arr['name'] = $this->iconv($row['kind_name']);
                $arr['teacher_sn'] = $row['teacher_sn'];
                $this->fromArray('comment_kind',$arr);
            }


            $query = "SELECT a.*,b.teacher_sn FROM comment a LEFT JOIN teacher_base b ON a.teacher_id=b.teach_id  ";
//echo $query;
            $res = $this->_sfs3Pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
            foreach($res as $row) {
                $arr = array();
                $arr['subject_name'] = $row['subject'];
                $arr['kind_sn'] = $row['kind'];
                $arr['level_sn'] = $row['level'];
                $arr['properey'] = $row['property'];
                $arr['text'] = $this->iconv($row['comm']);
                $arr['teacher_sn'] = $row['teacher_sn'];
                $this->fromArray('comment',$arr);
            }
        }

        $log['success_count'] = $success_count;
        $log['error_count'] = $error_count;
        $log['memo'] = '評語';
        $log['upgrade_time']    = date("Y-m-d h:i:s");

        $this->finishUpgrade($log);


    }
}